package Chapter9;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.Assert.*;

/**
 * Created by m.zabarylo on 10/13/2014.
 */
public class HTML5LocalStorage {

    private WebDriver driver;
    private StringBuffer verificationErrors = new StringBuffer();
    String lastName;
    JavascriptExecutor jsExecutor;

    @Before
    public void setUp()
    {
        driver = new ChromeDriver();
        driver.get("http://dl.dropbox.com/u/55228056/html5storage.html");
    }
    @Test
    public void testHTML5LocalStorage() throws Exception
    {
        String lastName;
        String secondName;

        JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
        lastName = (String) jsExecutor.executeScript("return localStorage.lastname;");
        assertEquals("Smith", lastName);
       // secondName = (String) jsExecutor.executeScript("localStorage.lastname = 'Max';");
       // assertEquals("Max", secondName);
    }
    @After
    public void tearDown()
    {
       // driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if(!"".equals(verificationErrorString))
        {
            fail(verificationErrorString);
        }
    }
}
